package com.ssx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ssx.entity.Customervisit;
import com.ssx.entity.Employees;
import com.ssx.mapper.CustomervisitMapper;
import com.ssx.service.ICustomervisitService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ssx
 * @since 2020-10-24
 */
@Service
@Transactional
public class CustomervisitServiceImpl extends ServiceImpl<CustomervisitMapper, Customervisit> implements ICustomervisitService {

    @Autowired
    private CustomervisitMapper customervisitMapper;

    @Override
    public List<Customervisit> listFromEmp(int start, int pagesize, String search, int empid) {
        return customervisitMapper.listFromEmp(new QueryWrapper<Customervisit>().eq("employees.empid",empid)
                .and(i->i.like("employees.name", search).or().like("content", search).or().like("customer.cusName", search)).last(" limit " + start + "," + pagesize));
    }

    @Override
    public int countFromEmp(String search, int empid) {
        return customervisitMapper.countFromEmp(new QueryWrapper<Customervisit>().eq("employees.empid",empid)
                .and(i->i.like("employees.name", search).or().like("content", search).or().like("customer.cusName", search)));
    }

    @Override
    public List<Customervisit> listFromManger(int start, int pagesize, String search) {
        return customervisitMapper.listFromManger(new QueryWrapper<Customervisit>().like("name", search)
                .or().like("content", search).or().like("customer.cusName", search)
                .last(" limit " + start + "," + pagesize));
    }

    @Override
    public int countFromManger(String search) {
        return customervisitMapper.countFromEmp(new QueryWrapper<Customervisit>()
                .like("employees.name", search).or().like("content", search).or().like("customer.cusName", search));
    }


}
